package com.sealer.pattern.behavioral.iterator;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Created by sealer on 17/04/06.
 * Iterator遍历HashMap示例
 */
public class Main {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("1", "one");
        map.put("2", "two");
        map.put("3", "three");
        map.put("4", "four");
        map.put("5", "five");
        map.put("6", "six");

        Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> entry = iterator.next();
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println("key : " + key + "\t value : " + value);
        }
    }
}
